﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;

namespace RollbackLib.src.utils
{
    public class Mailer
    {
        public static void sendEmail(string smtpHost, int smtpPort, bool usesSsl, string toAddress, string password,string fromAddress, string subject,string body)
        {
            System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(toAddress, 
                toAddress, 
                subject, 
                body);
            MyMailMessage.IsBodyHtml = true;
            
            System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(toAddress,password);
            System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(smtpHost, smtpPort);
            mailClient.EnableSsl = usesSsl;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = mailAuthentication;
            mailClient.Send(MyMailMessage);
        }

        public static void sendUsingGmail(string loginEmailId,string password,string to,string subject,string body) 
        {
            sendEmail("smtp.gmail.com", 587, true, loginEmailId,password,to,subject,body);
        }
    }
}
